package com.kyb.cms.module.config.web.rpc;

import com.kyb.cms.util.oss.AliYunOssUtil;
import org.armada.galileo.mvc_plus.domain.UploadResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;
import java.nio.charset.StandardCharsets;

/**
 * @author xiaobo
 * @date 2023/11/6 14:16
 */
@Controller
public class ResourceRpc {

    @Autowired
    private AliYunOssUtil aliYunOssUtil;

    public void uploadJson(String fileName, String jsonContent) {
        String objectName = "kyb_office/" + fileName;
        aliYunOssUtil.upload(objectName, jsonContent.getBytes(StandardCharsets.UTF_8));
    }

    public UploadResult uploadFile(HttpServletRequest request) throws Exception {
        return aliYunOssUtil.uploadByServletRequest("image", false, request);
    }

}
